{extend name="Base:base" /}
{block name="title"}<strong class="am-text-primary am-text-lg">系统</strong> / <small> 菜单管理 </small>{/block}
{block name="content"}
<style>
    .am-btn-group .am-btn-default, .am-btn-group-stacked .am-btn-default{
        background-color: #ffffff;
    }
    a.am-btn-default:visited{
        color: #3bb4f2;
    }
</style>
<div class="am-g">
    <div class="am-u-sm-12">
        <a class="am-btn am-btn-sm am-btn-primary am-radius" href="{:url('admin/menu/add')}"> 新增 </a>
        <table class="am-table am-table-striped am-table-hover table-main">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>名称</th>
                    <th>分组</th>
                    <th>链接</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
            {volist name="list" id="menu"}
                <tr>
                    <td>{$menu.id}</td>
                    <td>{$menu.title}</td>
                    <td></td>
                    <td>{$menu.url}</td>
                    <td>
                        {if condition="$menu.status == 0 "} 正在使用
                        {else /} 禁用
                        {/if}
                    </td>
                    <td>
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">
                                <a class="am-btn am-btn-default am-btn-xs am-text-secondary" href="{:url('admin/menu/edit',['id'=>$menu.id])}"><span class="am-icon-pencil-square-o"></span> 编辑</a>
                                <button class="am-btn am-btn-default am-btn-xs am-text-warning am-hide-sm-only"><span class="am-icon-copy"></span> 禁用</button>
                                <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="del({$menu.id})"><span class="am-icon-trash-o"></span> 删除</button>
                            </div>
                        </div>
                    </td>
                </tr>
                {if condition="isset($menu['_child'])"}
                    {volist name="$menu['_child']" id="menuChild"}
                    <tr>
                        <td>{$menuChild.id}</td>
                        <td> └─ {$menuChild.title}</td>
                        <td>{$menu.title}</td>
                        <td>{$menuChild.url}</td>
                        <td>
                            {if condition="$menuChild.status == 0 "} 正在使用
                            {else /} 禁用
                            {/if}
                        </td>
                        <td>
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <a class="am-btn am-btn-default am-btn-xs am-text-secondary" href="{:url('admin/menu/edit',['id'=>$menuChild.id])}"><span class="am-icon-pencil-square-o"></span> 编辑</a>
                                    <button class="am-btn am-btn-default am-btn-xs am-text-warning am-hide-sm-only"><span class="am-icon-copy"></span> 禁用</button>
                                    <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="del({$menuChild.id})"><span class="am-icon-trash-o"></span> 删除</button>
                                </div>
                            </div>
                        </td>
                    </tr>
                    {/volist}
                {/if}
            {/volist}
            </tbody>
        </table>
    </div>
</div>
<script>
    //删除
    function del(id) {
        var r = confirm('确定删除？');
        if(r){
            $.get("{:url('admin/menu/del')}",{id:id},function(data) {
                console.log(data);
                if(data.code == 1){
                    location.reload()
                }else{
                    alert('删除失败，请检查')
                }
            })
        }
    }
</script>
{/block}